/***************************************************************************
 创建者: 华磊
 开始时间: 2019.9.20
 copyright: (C) 华友高科
 ***************************************************************************/
#include "mainwindowtestmanage.h"
#include "ui_mainwindowtestmanage.h"

#include "mainwindowfleettest.h"
#include <QMessageBox>

MainWindowTestManage::MainWindowTestManage(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindowTestManage)
{
    ui->setupUi(this);

}

MainWindowTestManage::~MainWindowTestManage()
{
    delete ui;
}

int MainWindowTestManage::addAgvTestWidget(AgvConnectInfo infoIn)
{

    MainWindowFleetTest *agv1=new MainWindowFleetTest(infoIn,this);
    QString tmpTitle="id";
    tmpTitle+=QString::number(infoIn.agvId)+" |"+infoIn.agvName+" |"+infoIn.agvIp;
    ui->tabWidget_agv->addTab(agv1,tmpTitle);
    agvTestList.append(agv1);
    connect(agv1,SIGNAL(sig_pub_agv_position(int,QString,double,double,double,QStringList, int))
            ,this,SIGNAL(sig_pub_agv_position(int,QString,double,double,double,QStringList, int)));
    agv1->connectServerForUser();
}

void MainWindowTestManage::on_pushButton_addAgv_clicked()
{
    AgvConnectInfo info;
    info.agvId=ui->lineEdit_agvId->text().toInt();
    info.agvIp=ui->lineEdit_serverIp->text();
    info.agvName=ui->lineEdit_agvName->text();
    info.port=ui->lineEdit_port->text().toInt();

    for(int i=0;i<agvTestList.size();i++)
    {
        AgvConnectInfo tmpInfo=agvTestList[i]->getAgvInfo();
        if(tmpInfo.agvId==info.agvId)
        {
           QMessageBox::information(NULL, "information", "agvId重复了！", QMessageBox::Yes );
           return ;
        }
        if(tmpInfo.agvIp==info.agvIp)
        {
           QMessageBox::information(NULL, "information", "agvIp重复了！", QMessageBox::Yes );
            return ;
        }
        if(tmpInfo.agvName==info.agvName)
        {
           QMessageBox::information(NULL, "information", "agvName重复了！", QMessageBox::Yes );
            return ;
        }
    }

    addAgvTestWidget(info);

}
